package com.fkcai.hansoul.model.vo.post;

import com.fkcai.hansoul.model.entity.Post;
import com.fkcai.hansoul.model.entity.User;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.List;

@Data
public class PostFullInfoVo{
	private Integer postId;         // 帖子 id
	private String title;           // 标题
	private String content;         // 内容
	private LocalDateTime createTime;   //创建时间
	private Integer categoryId;    // 类别 id
	private String postStatus;      // 帖子状态
	private Integer viewCount;        // 浏览次数
	private Integer likeCount;        // 点赞数
	private Integer commentCount;     // 评论数
	private Integer shareCount;       // 分享次数
	private String location;          // 位置
	
	private List<String> imageUrls; // 图片地址列表
	
	private UserInfo user;
	
	/**
	 * 嵌套用户信息
	 */
	@Data
	public static class UserInfo {
		private Integer userId;
		private String username;     // 用户名
		private String avatarUrl;     // 头像URL
	
		public static UserInfo fromUser (User user) {
			UserInfo userInfo = new UserInfo();
			
			userInfo.setUserId(user.getUserId());
			userInfo.setUsername(user.getUsername());
			userInfo.setAvatarUrl(user.getAvatarUrl());
			
			return userInfo;
		}
	}
	
	public static PostFullInfoVo formPost (Post post, User user) {
		PostFullInfoVo postFullInfoVo = new PostFullInfoVo();
		
		postFullInfoVo.setPostId(post.getPostId());
		postFullInfoVo.setTitle(post.getTitle());
		postFullInfoVo.setContent(post.getContent());
		postFullInfoVo.setCreateTime(post.getCreateTime());
		postFullInfoVo.setCategoryId(post.getCategoryId());
		postFullInfoVo.setPostStatus(post.getPostStatus());
		postFullInfoVo.setViewCount(post.getViewCount());
		postFullInfoVo.setLikeCount(post.getLikeCount());
		postFullInfoVo.setCommentCount(post.getCommentCount());
		postFullInfoVo.setShareCount(post.getShareCount());
		postFullInfoVo.setLocation(post.getLocation());
		
		return postFullInfoVo;
	}
	
}
